package com.hut.oa.model.bean;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
/**
 * 职位表
 * @author 潘寻毅
 *
 */
@Entity
@Table(name="dept_office")
public class DeptOffice {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="do_id")
	private Long id;//职位id
	
	@Column(name="do_name",nullable=false)
	private String name;//职位名称
	
	@ManyToOne()
	@JoinColumn(name="do_leader_id")
	private DeptOffice leader;//归属哪个职位管
	
	@OneToMany
	@Transient
	private List<DeptOffice> children;//下属
	
	@Column(name="do_sal_base")
	private Double salBase;//岗位薪酬
	
	@JoinColumn(name="do_dept_id")
	@ManyToOne
	private Dept dept;//部门id
	
	@JsonIgnore
	@OneToMany(cascade=CascadeType.REFRESH,mappedBy="deptOffice",fetch=FetchType.LAZY)
	private List<User> users;//该职位下所有员工
	
	/*@ManyToMany(cascade=CascadeType.REFRESH)
	@JoinTable(name = "role_office",
	    joinColumns = {
	            @JoinColumn(name = "ro_office_id")
	    }, inverseJoinColumns = {
	    @JoinColumn(name = "ro_role_id")
	})
	private List<Role> roles;*/

	public DeptOffice() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public DeptOffice getLeader() {
		return leader;
	}

	public void setLeader(DeptOffice leader) {
		this.leader = leader;
	}

	public Double getSalBase() {
		return salBase;
	}

	public void setSalBase(Double salBase) {
		this.salBase = salBase;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}
	
	public List<DeptOffice> getChildren() {
		return children;
	}

	public void setChildren(List<DeptOffice> children) {
		this.children = children;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return "DeptOffice [id=" + id + ", name=" + name + ", salBase=" + salBase + "]";
	}
}
